# http://www.xbiquge.la/13/13959/5939025.html

import requests

url = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1604395439298&di=c2f091dd01b16923fcad2c43819aea29&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201901%2F26%2F20190126232348_wVKGJ.thumb.700_0.jpeg'

r = requests.get(url=url)

# 将requests.get对象转换成utf-8进行解码
# r.encoding = 'utf-8'

# text方法返回的是数据文本，str类型
print(r.text)

# #content方法返回的是二进制  图片和视频一类的就返回这个
print(r.content)
enc = r.content

# # 将二进制转换成str类型
b'123'.decode('utf-8')

# # 将字符串转换成二进制
'123'.encode('utf-8')


with open('nice.png', 'wb') as img:
    img.write(enc)
